<?php

/**
 * This is the model class for table "{{news}}".
 *
 * The followings are the available columns in table '{{news}}':
 * @property integer $id
 * @property integer $type_new_id
 * @property integer $user_id
 * @property string $title
 * @property string $summary_content
 * @property string $detail_content
 * @property string $images
 * @property string $create_datetime
 * @property string $update_datetime
 * @property string $exp_date
 * @property integer $number_view
 * @property integer $show
 * @property integer $del_flg
 *
 * The followings are the available model relations:
 * @property NewsType[] $newsTypes
 */
class News extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{news}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_id, title, summary_content, detail_content, images, create_datetime', 'required'),
			array('type_new_id, user_id, number_view, show, del_flg', 'numerical', 'integerOnly'=>true),
			array('title', 'length', 'max'=>200),
			array('images', 'length', 'max'=>50),
			array('update_datetime, exp_date', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, type_new_id, user_id, title, summary_content, detail_content, images, create_datetime, update_datetime, exp_date, number_view, show, del_flg', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'newsTypes' => array(self::HAS_MANY, 'NewsType', 'news_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'type_new_id' => 'Type New',
			'user_id' => 'User',
			'title' => 'Title',
			'summary_content' => 'Summary Content',
			'detail_content' => 'Detail Content',
			'images' => 'Images',
			'create_datetime' => 'Create Datetime',
			'update_datetime' => 'Update Datetime',
			'exp_date' => 'Exp Date',
			'number_view' => 'Number View',
			'show' => 'Show',
			'del_flg' => 'Del Flg',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('type_new_id',$this->type_new_id);
		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('summary_content',$this->summary_content,true);
		$criteria->compare('detail_content',$this->detail_content,true);
		$criteria->compare('images',$this->images,true);
		$criteria->compare('create_datetime',$this->create_datetime,true);
		$criteria->compare('update_datetime',$this->update_datetime,true);
		$criteria->compare('exp_date',$this->exp_date,true);
		$criteria->compare('number_view',$this->number_view);
		$criteria->compare('show',$this->show);
		$criteria->compare('del_flg',$this->del_flg);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return News the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
